package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dto.ArticuloDTO;

import business.LaCorunaDelegator;

/**
 * Servlet implementation class for Servlet: ArticuloCompletoAjax
 *
 */
 public class ArticuloCompletoAjax extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   private static final String AJAX_RENDER = "/WEB-INF/jsp/articulo_ajax.jsp";
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ArticuloCompletoAjax() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		LaCorunaDelegator delegator = LaCorunaDelegator.getInstance();
		String articulo_id = request.getParameter("articulo_id");
		Integer articulo_ref = Integer.parseInt(articulo_id);
		ArticuloDTO articulo= delegator.getArticulo(articulo_ref);
		request.setAttribute("articulo", articulo);
		getServletContext().getRequestDispatcher(AJAX_RENDER).forward(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}   	  	    
}